package com.shengcheng.controller;

import com.shengcheng.entity.RechargeInfo;
import com.shengcheng.entity.UserAccountDetail;
import com.shengcheng.login.TingShuLogin;
import com.shengcheng.query.AlbumInfoQuery;
import com.shengcheng.result.RetVal;
import com.shengcheng.service.RechargeInfoService;
import com.shengcheng.service.UserAccountDetailService;
import com.shengcheng.util.AuthContextHolder;
import com.shengcheng.vo.AccountLockVo;
import com.shengcheng.vo.AlbumTempVo;
import com.shengcheng.vo.RechargeInfoVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 充值信息 前端控制器
 * </p>
 *
 * @author 强哥
 * @since 2023-12-16
 */
@Tag(name = "充值管理")
@RestController
@RequestMapping("api/account/recharge")
public class RechargeInfoController {
    @Autowired
    private RechargeInfoService rechargeInfoService;
    @Autowired
    private UserAccountDetailService accountDetailService;
    @TingShuLogin
    @Operation(summary = "提交充值")
    @PostMapping("saveRecharge")
    public RetVal saveRecharge(@RequestBody RechargeInfoVo rechargeInfoVo) {
        Map<String, Object> retMap = rechargeInfoService.saveRecharge(rechargeInfoVo);
        return RetVal.ok(retMap);
    }

    @Operation(summary = "根据订单号获取充值记录")
    @GetMapping("getRechargeInfo/{orderNo}")
    public RetVal<RechargeInfo> getRechargeInfo(@PathVariable String orderNo) {
        LambdaQueryWrapper<RechargeInfo> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(RechargeInfo::getOrderNo, orderNo);
        RechargeInfo rechargeInfo = rechargeInfoService.getOne(wrapper);
        return RetVal.ok(rechargeInfo);
    }

    //http://127.0.0.1/api/account/recharge/getRecordByPage/1/10/1201
    @TingShuLogin
    @Operation(summary = "获取用户充值记录")
    @GetMapping("getRecordByPage/{pageNum}/{pageSize}/{tradeType}")
    public RetVal getRecordByPage(
            @PathVariable Long pageNum,
            @PathVariable Long pageSize,
            @PathVariable String tradeType) {
        IPage<UserAccountDetail> pageParam = new Page<>(pageNum, pageSize);
        accountDetailService.getUserAccountDetailByPage(pageParam,tradeType);
        return RetVal.ok(pageParam);
    }
}
